import javax.swing.*;

import java.awt.*;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

@SuppressWarnings("serial")
public class mainFrame extends JFrame {

    static int UIoffset = 13 * 32;

    int selectPosition;
    static int element;
    int menu;
    JPanel selectElem;
    static JLabel selectLabel;

    static Integer waterIcon;
    static Integer fireIcon;
    static Integer earthIcon;
    static Integer lngIcon;
    static JLabel waterCount;
    static JLabel fireCount;
    static JLabel earthCount;
    static JLabel lngCount;
    static JPanel addElem;
    static JLabel addLabel;
    JPanel menuElem;
    static JPanel HPPanel;
    static JLabel orbArray[];

    Player player;

    mainFrame() {
        super("Toot's Adventure");

        // cast the JContentPane to JPanel
        JPanel contentPane = (JPanel) this.getContentPane();
        contentPane.setOpaque(false);
        this.setSize(416, 516);

        waterIcon = 1;
        fireIcon = 1;
        earthIcon = 1;
        lngIcon = 1;

        //create a map that could be used as the background
        MapSquare[][] map2 = new MapSquare[13][13];
        for (int i = 0; i < 13; i++) {
            for (int j = 0; j < 13; j++) {
                map2[i][j] = new MapSquare();
                //add boundaries and exits if proper
                if ((i == 0 || j == 0 || i == 12 || j == 12)) {
                    // create a new object at (i,j)
                    if ((i == 0 && j == 6)) {
                        map2[i][j].gameObject = new Exit(null, i, j, 6, 6);
                    } else {
                        map2[i][j].gameObject = BoundaryCreator.tree(i, j);
                    }
                    map2[i][j].update();
                }
            }
        }
        map2[3][3].gameObject = MobCreator.EarthElemental1(3, 3);
        map2[3][3].update();

        //create the first map that we use, basic border or rocks
        player = new Player(9, 2);
        GameObject.player = player;
        MapSquare[][] map = new MapSquare[13][13];
        for (int i = 0; i < 13; i++) {
            for (int j = 0; j < 13; j++) {
                map[i][j] = new MapSquare();
                if ((i == 0 || j == 0 || i == 12 || j == 12)) {
                    map[i][j].gameObject = BoundaryCreator.rock(i, j);
                    map[i][j].update();
                }
                
            }
        }
        
        //add objects to the map
        map[9][2].gameObject = player;
        map[9][2].update();        
        map[3][7].gameObject = MobCreator.FireTurret(3, 7, Direction.Right);
        map[3][7].update();
        map[1][7].gameObject=MobCreator.EarthElemental2(1, 7);
        map[1][7].update();
        map[5][5].gameObject=BoundaryCreator.rock(5, 5);
        map[5][5].update();
        map[10][10].gameObject=BoundaryCreator.rock(10,10);
        map[10][10].update();
        map[11][10].gameObject=BoundaryCreator.rock(11,10);
        map[11][10].update();
        GameObject.loadNewMap(map);
        GameObject.gameObjects.add(MobCreator.Grunt(7, 9));


        //create new GridBagConstrains for each of the rows of the map
        ImageIcon levelSquare = new ImageIcon("src/images/32.jpg");
        JLayeredPane Level = new JLayeredPane();
        Level.setLayout(new GridBagLayout());
        GridBagConstraints row1 = new GridBagConstraints();
        GridBagConstraints row2 = new GridBagConstraints();
        GridBagConstraints row3 = new GridBagConstraints();
        GridBagConstraints row4 = new GridBagConstraints();
        GridBagConstraints row5 = new GridBagConstraints();
        GridBagConstraints row6 = new GridBagConstraints();
        GridBagConstraints row7 = new GridBagConstraints();
        GridBagConstraints row8 = new GridBagConstraints();
        GridBagConstraints row9 = new GridBagConstraints();
        GridBagConstraints row10 = new GridBagConstraints();
        GridBagConstraints row11 = new GridBagConstraints();
        GridBagConstraints row12 = new GridBagConstraints();
        GridBagConstraints row13 = new GridBagConstraints();

        //for each row, add the MapSquare to it on both the 
        //regular and foreGround JLabels
        row1.fill = GridBagConstraints.BOTH;
        row1.weightx = 1.0;
        row1.gridy = 0;
        for (int i = 0; i < 12; i++) {
            row1.gridx = i;
            Level.add(GameObject.map[0][i], row1, 0);
            Level.add(GameObject.map[0][i].foreGround, row1, 2);
        }
        row1.gridwidth = GridBagConstraints.REMAINDER;
        row1.gridx = 12;
        Level.add(GameObject.map[0][12], row1, 0);
        Level.add(GameObject.map[0][12].foreGround, row1, 2);

        row2.fill = GridBagConstraints.BOTH;
        row2.weightx = 1.0;
        row2.gridy = 1;
        for (int i = 0; i < 12; i++) {
            row2.gridx = i;
            Level.add(GameObject.map[1][i], row2, 0);
            Level.add(GameObject.map[1][i].foreGround, row2, 1);
        }
        row2.gridwidth = GridBagConstraints.REMAINDER;
        row2.gridx = 12;
        Level.add(GameObject.map[1][12], row2, 0);
        Level.add(GameObject.map[1][12].foreGround, row2, 2);

        row3.fill = GridBagConstraints.BOTH;
        row3.weightx = 1.0;
        row3.gridy = 2;
        for (int i = 0; i < 12; i++) {
            row3.gridx = i;
            Level.add(GameObject.map[2][i], row3, 0);
            Level.add(GameObject.map[2][i].foreGround, row3, 1);
        }
        row3.gridwidth = GridBagConstraints.REMAINDER;
        row3.gridx = 12;
        Level.add(GameObject.map[2][12], row3, 0);
        Level.add(GameObject.map[2][12].foreGround, row3, 2);

        row4.fill = GridBagConstraints.BOTH;
        row4.weightx = 1.0;
        row4.gridy = 3;
        for (int i = 0; i < 12; i++) {
            row4.gridx = i;
            Level.add(GameObject.map[3][i], row4, 0);
            Level.add(GameObject.map[3][i].foreGround, row4, 1);
        }
        row4.gridwidth = GridBagConstraints.REMAINDER;
        row4.gridx = 12;
        Level.add(GameObject.map[3][12], row4, 0);
        Level.add(GameObject.map[3][12].foreGround, row4, 2);

        row5.fill = GridBagConstraints.BOTH;
        row5.weightx = 1.0;
        row5.gridy = 4;
        for (int i = 0; i < 12; i++) {
            row5.gridx = i;
            Level.add(GameObject.map[4][i], row5, 0);
            Level.add(GameObject.map[4][i].foreGround, row5, 1);
        }
        row5.gridwidth = GridBagConstraints.REMAINDER;
        row5.gridx = 12;
        Level.add(GameObject.map[4][12], row5, 0);
        Level.add(GameObject.map[4][12].foreGround, row5, 2);

        row6.fill = GridBagConstraints.BOTH;
        row6.weightx = 1.0;
        row6.gridy = 5;
        for (int i = 0; i < 12; i++) {
            row6.gridx = i;
            Level.add(GameObject.map[5][i], row6, 0);
            Level.add(GameObject.map[5][i].foreGround, row6, 1);
        }
        row6.gridwidth = GridBagConstraints.REMAINDER;
        row6.gridx = 12;
        Level.add(GameObject.map[5][12], row6, 0);
        Level.add(GameObject.map[5][12].foreGround, row6, 2);

        row7.fill = GridBagConstraints.BOTH;
        row7.weightx = 1.0;
        row7.gridy = 6;
        for (int i = 0; i < 12; i++) {
            row7.gridx = i;
            Level.add(GameObject.map[6][i], row7, 0);
            Level.add(GameObject.map[6][i].foreGround, row7, 1);
        }
        row7.gridwidth = GridBagConstraints.REMAINDER;
        row7.gridx = 12;
        Level.add(GameObject.map[6][12], row7, 0);
        Level.add(GameObject.map[6][12].foreGround, row7, 2);

        row8.fill = GridBagConstraints.BOTH;
        row8.weightx = 1.0;
        row8.gridy = 7;
        for (int i = 0; i < 12; i++) {
            row8.gridx = i;
            Level.add(GameObject.map[7][i], row8, 0);
            Level.add(GameObject.map[7][i].foreGround, row8, 1);
        }
        row8.gridwidth = GridBagConstraints.REMAINDER;
        row8.gridx = 12;
        Level.add(GameObject.map[7][12], row8, 0);
        Level.add(GameObject.map[7][12].foreGround, row8, 2);

        row9.fill = GridBagConstraints.BOTH;
        row9.weightx = 1.0;
        row9.gridy = 8;
        for (int i = 0; i < 12; i++) {
            row9.gridx = i;
            Level.add(GameObject.map[8][i], row9, 0);
            Level.add(GameObject.map[8][i].foreGround, row9, 1);
        }
        row9.gridwidth = GridBagConstraints.REMAINDER;
        row9.gridx = 12;
        Level.add(GameObject.map[8][12], row9, 0);
        Level.add(GameObject.map[8][12].foreGround, row9, 2);

        row10.fill = GridBagConstraints.BOTH;
        row10.weightx = 1.0;
        row10.gridy = 9;
        for (int i = 0; i < 12; i++) {
            row10.gridx = i;
            Level.add(GameObject.map[9][i], row10, 0);
            Level.add(GameObject.map[9][i].foreGround, row10, 1);
        }
        row10.gridwidth = GridBagConstraints.REMAINDER;
        row10.gridx = 12;
        Level.add(GameObject.map[9][12], row10, 0);
        Level.add(GameObject.map[9][12].foreGround, row10, 2);

        row11.fill = GridBagConstraints.BOTH;
        row11.weightx = 1.0;
        row11.gridy = 10;
        for (int i = 0; i < 12; i++) {
            row11.gridx = i;
            Level.add(GameObject.map[10][i], row11, 0);
            Level.add(GameObject.map[10][i].foreGround, row11, 1);
        }
        row11.gridwidth = GridBagConstraints.REMAINDER;
        row11.gridx = 12;
        Level.add(GameObject.map[10][12], row11, 0);
        Level.add(GameObject.map[10][12].foreGround, row11, 2);

        row12.fill = GridBagConstraints.BOTH;
        row12.weightx = 1.0;
        row12.gridy = 11;
        for (int i = 0; i < 12; i++) {
            row12.gridx = i;
            Level.add(GameObject.map[11][i], row12, 0);
            Level.add(GameObject.map[11][i].foreGround, row12, 1);
        }
        row12.gridwidth = GridBagConstraints.REMAINDER;
        row12.gridx = 12;
        Level.add(GameObject.map[11][12], row12, 0);
        Level.add(GameObject.map[11][12].foreGround, row12, 2);

        row13.fill = GridBagConstraints.BOTH;
        row13.weightx = 1.0;
        row13.gridy = 12;
        for (int i = 0; i < 12; i++) {
            row13.gridx = i;
            Level.add(GameObject.map[12][i], row13, 0);
            Level.add(GameObject.map[12][i].foreGround, row13, 1);
        }
        row13.gridwidth = GridBagConstraints.REMAINDER;
        row13.gridx = 12;
        Level.add(GameObject.map[12][12], row13, 0);
        Level.add(GameObject.map[12][12].foreGround, row13, 2);

        // Set bounds for the Level Panel
        Level.setBounds(0, 0, levelSquare.getIconWidth() * 13, levelSquare
                .getIconHeight() * 13);

        // UI Background Panel
        JPanel BGPanel = new JPanel(null);
        JLabel BGLabel = null;
        ImageIcon BG = new ImageIcon("src/images/UI.png");
        BGLabel = new JLabel(BG);
        BGPanel.add(BGLabel);
        BGLabel.setBounds(0, 0, BG.getIconWidth(), BG.getIconHeight());
        BGPanel.setBounds(0, UIoffset, BG.getIconWidth(), BG.getIconHeight());

        // HP Panel
        HPPanel = new JPanel(new GridBagLayout());
        ImageIcon HPBar = new ImageIcon("src/images/hpfull.png");
        JLabel HPLabel = new JLabel(HPBar);
        HPLabel.setBounds(0, 0, 81, 5);
        HPPanel.add(HPLabel);
        HPPanel.setOpaque(false);
        HPPanel.setBounds(31, UIoffset + 26, 81, 5);

        // Add Element Panel
        addElem = new JPanel(new GridBagLayout());
        ImageIcon add = new ImageIcon("src/images/blank.png");
        addLabel = new JLabel(add);
        addLabel.setBounds(0, 0, add.getIconWidth(), add.getIconHeight());
        addElem.add(addLabel);
        addElem.setOpaque(false);
        addElem.setBounds(236, UIoffset + 5, add.getIconWidth(), add
                .getIconHeight());

        // Orb Count Panel
        // Water, 130
        // Fire, 165
        // Earth, 200
        // Lng, 236
        waterIcon = 0;
        fireIcon = 0;
        earthIcon = 0;
        lngIcon = 0;
        waterCount = new JLabel(new ImageIcon("src/images/0.png"));
        fireCount = new JLabel(new ImageIcon("src/images/0.png"));
        earthCount = new JLabel(new ImageIcon("src/images/0.png"));
        lngCount = new JLabel(new ImageIcon("src/images/0.png"));
        waterCount.setBounds(0, 0, 15, 15);
        fireCount.setBounds(0, 0, 15, 15);
        earthCount.setBounds(0, 0, 15, 15);
        lngCount.setBounds(0, 0, 15, 15);
        JPanel waterLabel = new JPanel(new GridBagLayout());
        waterLabel.add(waterCount);
        waterLabel.setOpaque(false);
        waterLabel.setBounds(130, UIoffset + 26, 15, 15);
        JPanel fireLabel = new JPanel(new GridBagLayout());
        fireLabel.add(fireCount);
        fireLabel.setOpaque(false);
        fireLabel.setBounds(165, UIoffset + 26, 15, 15);
        JPanel earthLabel = new JPanel(new GridBagLayout());
        earthLabel.add(earthCount);
        earthLabel.setOpaque(false);
        earthLabel.setBounds(200, UIoffset + 26, 15, 15);
        JPanel lngLabel = new JPanel(new GridBagLayout());
        lngLabel.add(lngCount);
        lngLabel.setOpaque(false);
        lngLabel.setBounds(236, UIoffset + 26, 15, 15);

        // Magic Orbs
        // Orb1, 30
        // Orb2, 44
        // Orb3, 58
        // Orb4, 72
        // Orb5, 86
        // Orb6, 100
        orbArray = new JLabel[6];
        for (int i = 0; i < 6; i++) {
            orbArray[i] = new JLabel(new ImageIcon("src/images/blank.png"));
        }
        JPanel orb1 = new JPanel(new GridBagLayout());
        orbArray[0].setBounds(0, 0, 15, 15);
        orb1.add(orbArray[0]);
        orb1.setOpaque(false);
        orb1.setBounds(30, UIoffset + 41, 15, 15);
        JPanel orb2 = new JPanel(new GridBagLayout());
        orbArray[1].setBounds(0, 0, 15, 15);
        orb2.add(orbArray[1]);
        orb2.setOpaque(false);
        orb2.setBounds(44, UIoffset + 41, 15, 15);
        JPanel orb3 = new JPanel(new GridBagLayout());
        orbArray[2].setBounds(0, 0, 15, 15);
        orb3.add(orbArray[2]);
        orb3.setOpaque(false);
        orb3.setBounds(58, UIoffset + 41, 15, 15);
        JPanel orb4 = new JPanel(new GridBagLayout());
        orbArray[3].setBounds(0, 0, 15, 15);
        orb4.add(orbArray[3]);
        orb4.setOpaque(false);
        orb4.setBounds(72, UIoffset + 41, 15, 15);
        JPanel orb5 = new JPanel(new GridBagLayout());
        orbArray[4].setBounds(0, 0, 15, 15);
        orb5.add(orbArray[4]);
        orb5.setOpaque(false);
        orb5.setBounds(86, UIoffset + 41, 15, 15);
        JPanel orb6 = new JPanel(new GridBagLayout());
        orbArray[5].setBounds(0, 0, 15, 15);
        orb6.add(orbArray[5]);
        orb6.setOpaque(false);
        orb6.setBounds(100, UIoffset + 41, 15, 15);

        // Select element
        element = 1;
        selectPosition = 133;
        selectElem = new JPanel(new GridBagLayout());
        ImageIcon select = new ImageIcon("src/images/select.png");
        selectLabel = new JLabel(select);
        selectLabel.setBounds(0, 0, select.getIconWidth(), select
                .getIconHeight());
        selectElem.add(selectLabel);
        selectElem.setOpaque(false);
        selectElem.setBounds(selectPosition, UIoffset + 9, select
                .getIconWidth(), select.getIconHeight());

        // Select menu
        menu = 1;
        menuElem = new JPanel(new GridBagLayout());
        ImageIcon menu = new ImageIcon("src/images/selectmenu.png");
        JLabel menuLabel = new JLabel(menu);
        menuLabel.setBounds(0, 0, menu.getIconWidth(), menu.getIconHeight());
        menuElem.add(menuLabel);
        menuElem.setOpaque(false);
        menuElem.setBounds(278, UIoffset + 13, menu.getIconWidth(), menu
                .getIconHeight());

        // Set up the panels in order
        JLayeredPane layeredPane = this.getLayeredPane();
        layeredPane.add(menuElem, new Integer(15));
        layeredPane.add(selectElem, new Integer(14));
        layeredPane.add(orb6, new Integer(13));
        layeredPane.add(orb5, new Integer(12));
        layeredPane.add(orb4, new Integer(11));
        layeredPane.add(orb3, new Integer(10));
        layeredPane.add(orb2, new Integer(9));
        layeredPane.add(orb1, new Integer(8));
        layeredPane.add(lngLabel, new Integer(7));
        layeredPane.add(earthLabel, new Integer(6));
        layeredPane.add(fireLabel, new Integer(5));
        layeredPane.add(waterLabel, new Integer(4));
        layeredPane.add(addElem, new Integer(3));
        layeredPane.add(HPPanel, new Integer(2));
        layeredPane.add(Level, new Integer(1));
        layeredPane.add(BGPanel, new Integer(0));

        // Add listener
        this.addKeyListener(new TootListener());

    }

    public void changeElement(int which) {
        // Water, 133
        // Fire, 168
        // Earth, 203
        // Lng, 239
        if (which == 1)
            selectElem.setBounds(133, UIoffset + 9, 10, 10);
        else if (which == 2)
            selectElem.setBounds(168, UIoffset + 9, 10, 10);
        else if (which == 3)
            selectElem.setBounds(203, UIoffset + 9, 10, 10);
        else if (which == 4)
            selectElem.setBounds(239, UIoffset + 9, 10, 10);
        element = which;
        changeOrbs(which);
    }

    public static void addElement(int which) {
        // Water, 130
        // Fire, 165
        // Earth, 200
        // Lng, 236
        if (which == element)
            selectLabel.setIcon(new ImageIcon("src/images/blank.png"));
        if (which == 1) {
            addElem.setBounds(130, UIoffset + 5, 15, 15);
            if (waterIcon < 6)
                updateElementCount(1, 1);
        } else if (which == 2) {
            addElem.setBounds(165, UIoffset + 5, 15, 15);
            if (fireIcon < 6)
                updateElementCount(2, 1);
        } else if (which == 3) {
            addElem.setBounds(200, UIoffset + 5, 15, 15);
            if (earthIcon < 6)
                updateElementCount(3, 1);
        } else if (which == 4) {
            addElem.setBounds(236, UIoffset + 5, 15, 15);
            if (lngIcon < 6)
                updateElementCount(4, 1);
        }
        if (which == element)
            selectLabel.setIcon(new ImageIcon("src/images/select.png"));
    }

    public static void updateElementCount(int which, int quant) {
        if (which == 1) {
            waterIcon += quant;
            String file = "src/images/" + waterIcon + ".png";
            waterCount.setIcon(new ImageIcon(file));
            if (which == element) {
                if (waterIcon == 0)
                    orbArray[0].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
                else
                    orbArray[waterIcon - 1].setIcon(new ImageIcon("src/images"
                            + "/water.png"));
            }
        } else if (which == 2) {
            fireIcon += quant;
            String file = "src/images/" + fireIcon + ".png";
            fireCount.setIcon(new ImageIcon(file));
            if (which == element) {
                if (fireIcon == 0)
                    orbArray[0].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
                else
                    orbArray[fireIcon - 1].setIcon(new ImageIcon("src/images"
                            + "/fire.png"));
            }
        } else if (which == 3) {
            earthIcon += quant;
            String file = "src/images/" + earthIcon + ".png";
            earthCount.setIcon(new ImageIcon(file));
            if (which == element) {
                if (earthIcon == 0)
                    orbArray[0].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
                else
                    orbArray[earthIcon - 1].setIcon(new ImageIcon("src/images"
                            + "/earth.png"));
            }
        } else if (which == 4) {
            lngIcon += quant;
            String file = "src/images/" + lngIcon + ".png";
            lngCount.setIcon(new ImageIcon(file));
            if (which == element) {
                if (lngIcon == 0)
                    orbArray[0].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
                else
                    orbArray[lngIcon - 1].setIcon(new ImageIcon("src/images"
                            + "/lng.png"));
            }
        }
    }

    public void selectMenu(int which) {
        // Menu1, 278-13
        // Menu2, 278-38
        // Menu3, 342-12
        // Menu4, 342-38
        if (which == 1) {
            menu = 1;
            menuElem.setBounds(278, UIoffset + 13, 10, 10);
        } else if (which == 2) {
            menu = 2;
            menuElem.setBounds(278, UIoffset + 38, 10, 10);
        } else if (which == 3) {
            menu = 3;
            menuElem.setBounds(342, UIoffset + 13, 10, 10);
        } else if (which == 4) {
            menu = 4;
            menuElem.setBounds(342, UIoffset + 38, 10, 10);
        }
    }

    public static void changeOrbs(int which) {
        if (which == 1) {
            for (int i = 0; i < 6; i++) {
                if (i < waterIcon) {
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/water.png"));
                } else
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
            }
        }
        if (which == 2) {
            for (int i = 0; i < 6; i++) {
                if (i < fireIcon) {
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/fire.png"));
                } else
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
            }
        }
        if (which == 3) {
            for (int i = 0; i < 6; i++) {
                if (i < earthIcon) {
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/earth.png"));
                } else
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
            }
        }
        if (which == 4) {
            for (int i = 0; i < 6; i++) {
                if (i < lngIcon) {
                    orbArray[i]
                            .setIcon(new ImageIcon("src/images" + "/lng.png"));
                } else
                    orbArray[i].setIcon(new ImageIcon("src/images"
                            + "/blank.png"));
            }
        }
    }

    public static void setHP(double percent) {
        percent = (81 * percent);
        HPPanel.setBounds(31, UIoffset + 26, (int) percent, 5);
    }

    public class TootListener implements KeyListener {

        boolean control;

        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_CONTROL) {
                control = true;
            }
            if (control) {
                if (arg0.getKeyCode() == KeyEvent.VK_UP) {
                    if (menu == 2)
                        selectMenu(1);
                    if (menu == 4)
                        selectMenu(3);
                }
                if (arg0.getKeyCode() == KeyEvent.VK_DOWN) {
                    if (menu == 1)
                        selectMenu(2);
                    if (menu == 3)
                        selectMenu(4);
                }
                if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
                    if (menu == 3)
                        selectMenu(1);
                    if (menu == 4)
                        selectMenu(2);
                }
                if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
                    if (menu == 1)
                        selectMenu(3);
                    if (menu == 2)
                        selectMenu(4);
                }
            } else {
                if (arg0.getKeyCode() == KeyEvent.VK_UP) {
                    GameObject.player.attack(Direction.Left);
                }
                if (arg0.getKeyCode() == KeyEvent.VK_DOWN) {
                    GameObject.player.attack(Direction.Right);
                }
                if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
                    GameObject.player.attack(Direction.Up);
                }
                if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
                    GameObject.player.attack(Direction.Down);
                }
            }

        }

        public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_CONTROL) {
                control = false;
            }
        }

        public void keyTyped(KeyEvent arg0) {
            char compare = arg0.getKeyChar();

            if (compare == '1') {
                changeElement(1);
                player.nextAttack(0);
            } else if (compare == '2') {
                changeElement(2);
                player.nextAttack(1);
            } else if (compare == '3') {
                changeElement(3);
                player.nextAttack(2);
            } else if (compare == '4') {
                changeElement(4);
                player.nextAttack(3);
            }

            if (compare == 'w')
                GameObject.player.move(Direction.Left);
            if (compare == 'a')
                GameObject.player.move(Direction.Up);
            if (compare == 's')
                GameObject.player.move(Direction.Right);
            if (compare == 'd')
                GameObject.player.move(Direction.Down);
        }

    }

}
